﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;

namespace SceneManager.Processors
{
    public class BlurProcessor : TextureProcessor
    {
        public int Radius { get; set; }

        private ScaleProcessor downScaleProcessor;
        private ScaleProcessor upScaleProcessor;

        public BlurProcessor(Game game, int radius) : base(game)
        {
            Radius = radius;

            downScaleProcessor = new ScaleProcessor(Game, Width / Radius, Height / Radius);
            upScaleProcessor = new ScaleProcessor(Game, Width, Height);

            Inputs.Add("Input", null);
            Outputs.Add("Output", null);
        }

        public override void Process(Camera camera, GameTime gameTime)
        {
#if DEBUG
            stopwatch.Restart();
#endif

            downScaleProcessor.Inputs["Input"] = Inputs["Input"];
            downScaleProcessor.Process(camera, gameTime);
            upScaleProcessor.Inputs["Input"] = downScaleProcessor.Outputs["Output"];
            upScaleProcessor.Process(camera, gameTime);
            Outputs["Output"] = upScaleProcessor.Outputs["Output"];

#if DEBUG
            processTimes.Enqueue((int)stopwatch.ElapsedTicks);
            while (processTimes.Count > 60)
                processTimes.Dequeue();
#endif
        }
    }
}
